<template>
	<view>
		<!-- 导航 -->
		<u-sticky @fixed="fixed=true" @unfixed="fixed=false" :h5-nav-height="0">
			<view class="bg-white">
				<view class="status_bar" style="background: #fff;"></view>
				<u-tabs style="width: 200rpx;margin-left: 24rpx;" :list="tabs" active-color="#EEBC80" font-size="32" :is-scroll="false"
				 :current="current" @change="change"></u-tabs>

				<view class="flex-row justify-center align-center" style="padding: 0 32rpx;">
					<view class="item" :class="{ active: active==k }" v-for="(i, k) in list" :key="k" @click="itemChange(k)">
						{{i.name}}
					</view>
				</view>
			</view>
		</u-sticky>

		<!-- 内容 -->
		<view :class="{ 'list-fixed': fixed }">
			<view class="list">
				<my-service :img="i.thumbnail" :title="i.product_name" :price="i.price" :exact="i.exact_price" :unit="i.unit" :rate="i.score" :tags="i.merchant.tags"
				 v-for="i in list[active].data" :key="i.id" :self="i.merchant.is_self" @click.native="$goto('/pages/service/detail?id=' + i.id)">
					<template v-slot:mid>
						<view class="flex-row justify-between align-center">
							<view class="my-order-sub">{{i.merchant.merchant_name}}</view>
							<view class="my-order-btn on">免费咨询</view>
						</view>
					</template>
				</my-service>
				
				<my-case :img="i.thumbnail" :title="i.case_name" :subTitle="i.desc" :tags="i.tags" v-for="i in list[active].case" :key="i.id"
				 :company="i.merchant.merchant_name" @click.native="$goto('/pages/case/detail?id=' + i.id)">
				</my-case>
			</view>

			<u-loadmore :status="list[active].status" bg-color="#EFF1F4" margin-top="30" margin-bottom="30"></u-loadmore>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabs: [{
					name: '服务',
					api: '/product/recommend/'
				}, {
					name: '案例',
					api: '/merchant/case/list/'
				}],
				list: [{
					name: '设计开发',
					type: 1,
					status: 'loadmore',
					data: [],
					case: []
				}, {
					name: '影视服务',
					type: 2,
					status: 'loadmore',
					data: [],
					case: []
				}, {
					name: '广告制作',
					type: 3,
					status: 'loadmore',
					data: [],
					case: []
				}, {
					name: '企划代理',
					type: 60,
					status: 'loadmore',
					data: [],
					case: []
				}, {
					name: '企咖服务',
					type: 4,
					status: 'loadmore',
					data: [],
					case: []
				}],
				current: 0,
				active: 0,
				fixed: false
			};
		},
		mounted() {
			this.getData()
		},
		methods: {
			change(index) {
				this.current = index;
				this.getData()
			},
			itemChange(index) {
				this.active = index
				this.getData()
			},
			getData() {
				let api = this.tabs[this.current].api
				let target = this.list[this.active]
				
				target.data = []
				target.status = 'loading'
				this.$u.get(api + target.type).then(res => {
					target.data = res.data.result.product
					target.case = res.data.result.case
					target.status = 'nomore'
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #EFF1F4;
	}
	.item {
		width: 160rpx;
		height: 44rpx;
		font-size: 22rpx;
		background: rgba(245, 245, 245, 1);
		border-radius: 2rpx;
		margin: 32rpx 6rpx;
		text-align: center;
		line-height: 44rpx;

		&.active {
			background: rgba(255, 246, 235, 1);
			color: #EEBC80;
		}
	}
	.list-fixed {
		min-height: calc(100vh - 244rpx);
	}
</style>
